-
-
Notifications
You must be signed in to change notification settings - Fork 631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modify register API to accept renderer functions #581
Modify register API to accept renderer functions #581
Conversation
@jtibbertsma Very intriguing!
@robwise @alexfedoseev We'll have to give this a close look in the coming weeks. However, please stay focused on F&G v2! We can potentially leverage this when we make a big push for performance after v2 is completed! |
@justin808 Sure, I'll work on a pr for react-webpack-rails-tutorial this weekend. |
@jtibbertsma I'm looking forward to seeing the changes! |
@jtibbertsma Any update? |
@justin808 I've been a bit busy this week. I should have some time to work on it today. |
@jtibbertsma Could have a simple example in |
@justin808 Sure, I'll work on it this week |
@jtibbertsma Keep me posted! |
@justin808 I added a simple integration test that shows that the renderer function gets called correctly. |
@jtibbertsma REALLY AWESOME. Let's address the comments! Reviewed 8 of 12 files at r1, 8 of 8 files at r4, 2 of 2 files at r5. CHANGELOG.md, line 8 at r5 (raw file):
reference the PR, as done below for other changes you can use the release 6.2.0 and change the bottom part showing the diff README.md, line 456 at r5 (raw file):
we should mention the README.md, line 476 at r5 (raw file):
we need to refer to the page on code splitting here docs/additional-reading/code-splitting.md, line 15 at r5 (raw file):
this is formatting so you have to scroll sideways a ton please see if you can change that docs/additional-reading/code-splitting.md, line 18 at r5 (raw file):
I'm a bit confused about the interaction between deferred rendering and react-router. Is the idea that a page is bookmarked, and react-router's deferred rendering counts as a first render, so that the server render and what's in react-router's deferred renders should be the same? It would be great to have some graphic or other explanation of this. What's not obvious is that we can server render what the deferred rendering will be. docs/additional-reading/code-splitting.md, line 26 at r5 (raw file):
Maybe use docs/additional-reading/code-splitting.md, line 42 at r5 (raw file):
We need to be very clear that RouterApp will handle calling ReactDOM to create the react element, attached to a DOM node. Should we be showing some docs/additional-reading/code-splitting.md, line 85 at r5 (raw file):
maybe:
docs/api/javascript-api.md, line 64 at r5 (raw file):
We might be able to throw an error if this is called on the server since we'll know we're server rendering with the rails context. node_package/src/ReactOnRails.js, line 114 at r5 (raw file):
Please move this next to the definition immediately below spec/dummy/client/app/startup/ManualRenderAppRenderer.jsx, line 12 at r5 (raw file):
I feel that we need the example to show react-router. We use react-router in the dummy apps. Another consideration is support for react-router v4. Comments from Reviewable |
I have one comment below. And also one more comment on the global API: I'm not a big fan of owning key deps (as Review status: all files reviewed at latest revision, 12 unresolved discussions. docs/additional-reading/code-splitting.md, line 85 at r5 (raw file):
I don't think the main point here is different webpack configs (as client/server configs are usually different regardless of whether or not code splitting is used), but the fact that it requires different Comments from Reviewable |
Review status: 13 of 18 files reviewed at latest revision, 12 unresolved discussions. docs/additional-reading/code-splitting.md, line 18 at r5 (raw file):
|
Review status: 13 of 18 files reviewed at latest revision, 12 unresolved discussions. docs/api/javascript-api.md, line 64 at r5 (raw file):
|
Review status: 13 of 18 files reviewed at latest revision, 12 unresolved discussions. spec/dummy/client/app/startup/ManualRenderAppRenderer.jsx, line 12 at r5 (raw file):
|
Looking good! Reviewed 5 of 5 files at r6. docs/additional-reading/code-splitting.md, line 18 at r5 (raw file):
|
@jtibbertsma I'd like to get this in the next release, maybe this weekend! |
Review status: all files reviewed at latest revision, 5 unresolved discussions. docs/additional-reading/code-splitting.md, line 85 at r5 (raw file):
|
Review status: 17 of 18 files reviewed at latest revision, 5 unresolved discussions. docs/additional-reading/code-splitting.md, line 18 at r5 (raw file):
|
Review status: 17 of 18 files reviewed at latest revision, 5 unresolved discussions. docs/additional-reading/code-splitting.md, line 58 at r6 (raw file):
|
@justin808 I've been thinking about this, and I've realized that there's actually no need to have a new API for this. Instead of having |
@jtibbertsma I look forward to seeing what you come up with! |
@jtibbertsma This is looking amazing. Keep me posted when you want more review. Reviewed 8 of 12 files at r8, 1 of 3 files at r9, 11 of 14 files at r12, 1 of 1 files at r13, 2 of 2 files at r14. docs/additional-reading/code-splitting.md, line 22 at r14 (raw file):
Cool! I just hope this is not to subtle. docs/additional-reading/code-splitting.md, line 51 at r14 (raw file):
I'd put a comment above this line and the file above, to highlight the difference! docs/additional-reading/code-splitting.md, line 60 at r14 (raw file):
and comment here on how RouterApp is two different imports given client vs server. docs/additional-reading/code-splitting.md, line 101 at r14 (raw file):
How does this fit into React Router v4? https://github.com/ReactTraining/react-router/tree/v4 I'm OK making this feature only work with v4. Or we should make the docs work with v3 and v4. CC: @alexfedoseev @robwise docs/additional-reading/code-splitting.md, line 107 at r14 (raw file):
FYI -- we're investigating alternatives to execJS. Possibly, @jtibbertsma, we could get you involved. docs/additional-reading/code-splitting.md, line 109 at r14 (raw file):
also point out to have different entry files for the server and client webpack configs docs/additional-reading/code-splitting.md, line 123 at r14 (raw file):
Suppose this is not done. How hard is it to debug this? Maybe show the error here so that a google search will find this page. node_package/src/serverRenderReactComponent.js, line 18 at r14 (raw file):
Let's make the error a bit more explicit, even including a doc link. node_package/tests/ComponentRegistry.test.js, line 59 at r14 (raw file):
How about a test with 2 params? spec/dummy/client/app/startup/DeferredRenderAppRenderer.jsx, line 3 at r14 (raw file):
how will this change with https://github.com/ReactTraining/react-router/tree/v4 ? spec/dummy/client/app/startup/DeferredRenderAppServer.jsx, line 38 at r14 (raw file):
Let's have some reference to these example files in the doc MD file. spec/dummy/spec/features/integration_spec.rb, line 176 at r8 (raw file):
we should uncomment the test Comments from Reviewable |
@@ -12,6 +12,7 @@ const devBuild = process.env.NODE_ENV !== 'production'; | |||
config.output = { | |||
filename: '[name]-bundle.js', | |||
path: '../app/assets/webpack', | |||
publicPath: '/assets/', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jtibbertsma Should we put the files separately for code splitting? i would think there would be another change to some webpack file.
Review status: all files reviewed at latest revision, 18 unresolved discussions. docs/additional-reading/code-splitting.md, line 22 at r14 (raw file): Previously, justin808 (Justin Gordon) wrote…
I like this way better than having a separate API. docs/additional-reading/code-splitting.md, line 51 at r14 (raw file): Previously, justin808 (Justin Gordon) wrote…
Done. docs/additional-reading/code-splitting.md, line 60 at r14 (raw file): Previously, justin808 (Justin Gordon) wrote…
Done. docs/additional-reading/code-splitting.md, line 101 at r14 (raw file): Previously, justin808 (Justin Gordon) wrote…
It's really annoying when libraries completely change their APIs. I suppose that all the docs will have to be updated for v4. I don't know how code splitting will work with v4 yet. I'll do some more research on it eventually. Anyway, it's still in alpha, so I'm not going to worry too much about this right now. docs/additional-reading/code-splitting.md, line 107 at r14 (raw file): Previously, justin808 (Justin Gordon) wrote…
Cool docs/additional-reading/code-splitting.md, line 109 at r14 (raw file): Previously, justin808 (Justin Gordon) wrote…
Done. docs/additional-reading/code-splitting.md, line 123 at r14 (raw file): Previously, justin808 (Justin Gordon) wrote…
If you don't put Another consideration is how you do error handling with code splitting. With webpack v1, there's really no way to implement error handling, but in v2 you can implement error handling by calling I went ahead and added part of this explanation and a possible error message that you might get. node_package/src/serverRenderReactComponent.js, line 18 at r14 (raw file): Previously, justin808 (Justin Gordon) wrote…
Done. node_package/tests/ComponentRegistry.test.js, line 59 at r14 (raw file): Previously, justin808 (Justin Gordon) wrote…
Do you have something in mind? I can't think of anything to test here other than checking that isRenderer key is set to true. spec/dummy/client/webpack.client.rails.build.config.js, line 15 at r14 (raw file): Previously, justin808 (Justin Gordon) wrote…
Do you mean that the code chunks should go to a different folder than app-bundle and vendor-bundle? spec/dummy/client/app/startup/DeferredRenderAppRenderer.jsx, line 3 at r14 (raw file): Previously, justin808 (Justin Gordon) wrote…
I'll have to look into it. spec/dummy/client/app/startup/DeferredRenderAppServer.jsx, line 38 at r14 (raw file): Previously, justin808 (Justin Gordon) wrote…
Done. spec/dummy/spec/features/integration_spec.rb, line 176 at r8 (raw file): Previously, justin808 (Justin Gordon) wrote…
Done. Comments from Reviewable |
This is super close to being ready. @jtibbertsma please see my comments and let me know if you want me to merge this. This is really an impressive PR! Reviewed 3 of 3 files at r15. docs/additional-reading/code-splitting.md, line 85 at r5 (raw file): Previously, jtibbertsma (Joseph Tibbertsma) wrote…
@jtibbertsma We really want the spec/dummy example to show code splitting on the client side. Why? This will show the usefulness of this technique! docs/additional-reading/code-splitting.md, line 101 at r14 (raw file): Previously, jtibbertsma (Joseph Tibbertsma) wrote…
@jtibbertsma The changes are really great and worth the churn. Yes, we will eventually update the docs. I think the technique is the same. docs/additional-reading/code-splitting.md, line 123 at r14 (raw file): Previously, jtibbertsma (Joseph Tibbertsma) wrote…
Webpack v2 is close enough to being published that it's worth considering for the documentation. node_package/src/serverRenderReactComponent.js, line 20 at r15 (raw file):
is this better than the code-spliting.md doc? node_package/tests/ComponentRegistry.test.js, line 59 at r14 (raw file): Previously, jtibbertsma (Joseph Tibbertsma) wrote…
that's exactly what I was thinking of, except, isRenderer should be false spec/dummy/client/webpack.client.rails.build.config.js, line 15 at r14 (raw file): Previously, jtibbertsma (Joseph Tibbertsma) wrote…
Not a separate folder, but we could have app-bundle-router, and app-bundle-route-b. Comments from Reviewable |
Review status: all files reviewed at latest revision, 9 unresolved discussions. docs/additional-reading/code-splitting.md, line 85 at r5 (raw file): Previously, justin808 (Justin Gordon) wrote…
I did put a code splitting example in spec/dummy. node_package/src/serverRenderReactComponent.js, line 20 at r15 (raw file): Previously, justin808 (Justin Gordon) wrote…
Yeah. The information there is more relevant to the error message, and it links to code-splitting.md node_package/tests/ComponentRegistry.test.js, line 59 at r14 (raw file): Previously, justin808 (Justin Gordon) wrote…
Ok, I see. I'll add another test Comments from Reviewable |
Review status: all files reviewed at latest revision, 9 unresolved discussions. docs/additional-reading/code-splitting.md, line 123 at r14 (raw file): Previously, justin808 (Justin Gordon) wrote…
Ok, I added a comment about error handling. node_package/tests/ComponentRegistry.test.js, line 59 at r14 (raw file): Previously, jtibbertsma (Joseph Tibbertsma) wrote…
I added another test case. spec/dummy/client/webpack.client.rails.build.config.js, line 15 at r14 (raw file): Previously, justin808 (Justin Gordon) wrote…
I think this is fine how it is. Comments from Reviewable |
@justin808 Ready to merge? Should I rebase and squash the commits? |
@jtibbertsma If you'd like to create a nice squashed commit with an awesome, that would be super! |
Reviewed 2 of 2 files at r16. Comments from Reviewable |
730bd9b
to
ebf7e61
Compare
Made the following changes to the node package: * ComponentRegistry.js: Modified register to detect generator functions with three arguments. Set the isRenderer key to true for these functions. * clientStartup.js: Added logic to delegate to renderer functions. * createReactElement.js: Now accepts an object instead of a component name. * serverRenderReactComponent.js: Throws an error if attempting to render a renderer function. * ReactOnRails.js: Change render function to call createReactElement with the component object. Doc changes: * README.md: Added section about renderer function under the section on generator functions. Moved the section on generator functions from the 'ReactOnRails View Helpers API' section to the 'Globally Exposing Your React Components' section. * Added a file code-splitting.md that describes how to use renderer functions to do code splitting with server rendering. Tests: * ComponentRegistry.test.js: Modified existing test cases to expect the isRenderer key to be false. Added a few test cases related to renderer functions. * serverRenderReactComponent.test.js: Show that an error gets thrown if trying to server render with a renderer function. * spec/dummy: Added two examples using rendering functions, one of which implements code splitting. Added three test to integration_spec.rb. Resolves: shakacode#477
ebf7e61
to
733cb2f
Compare
Made the following changes to the node package: * ComponentRegistry.js: Modified register to detect generator functions with three arguments. Set the isRenderer key to true for these functions. * clientStartup.js: Added logic to delegate to renderer functions. * createReactElement.js: Now accepts an object instead of a component name. * serverRenderReactComponent.js: Throws an error if attempting to render a renderer function. * ReactOnRails.js: Change render function to call createReactElement with the component object. Doc changes: * README.md: Added section about renderer function under the section on generator functions. Moved the section on generator functions from the 'ReactOnRails View Helpers API' section to the 'Globally Exposing Your React Components' section. * Added a file code-splitting.md that describes how to use renderer functions to do code splitting with server rendering. Tests: * ComponentRegistry.test.js: Modified existing test cases to expect the isRenderer key to be false. Added a few test cases related to renderer functions. * serverRenderReactComponent.test.js: Show that an error gets thrown if trying to server render with a renderer function. * spec/dummy: Added two examples using rendering functions, one of which implements code splitting. Added three test to integration_spec.rb. Resolves: shakacode#477
Made the following changes to the node package: * ComponentRegistry.js: Modified register to detect generator functions with three arguments. Set the isRenderer key to true for these functions. * clientStartup.js: Added logic to delegate to renderer functions. * createReactElement.js: Now accepts an object instead of a component name. * serverRenderReactComponent.js: Throws an error if attempting to render a renderer function. * ReactOnRails.js: Change render function to call createReactElement with the component object. Doc changes: * README.md: Added section about renderer function under the section on generator functions. Moved the section on generator functions from the 'ReactOnRails View Helpers API' section to the 'Globally Exposing Your React Components' section. * Added a file code-splitting.md that describes how to use renderer functions to do code splitting with server rendering. Tests: * ComponentRegistry.test.js: Modified existing test cases to expect the isRenderer key to be false. Added a few test cases related to renderer functions. * serverRenderReactComponent.test.js: Show that an error gets thrown if trying to server render with a renderer function. * spec/dummy: Added two examples using rendering functions, one of which implements code splitting. Added three test to integration_spec.rb. Resolves: shakacode#477
733cb2f
to
55ed923
Compare
@justin808 Done |
Reviewed 6 of 6 files at r17. Comments from Reviewable |
See Issue #477
This change is